#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    static QString pathname = "";

    connect(ui->push_button_1, &QPushButton::clicked, this, [=]() {
        // 从文件对话框中获取文件的路径
        pathname = QFileDialog::getOpenFileName(this, "Select File", "D\\Desktop");
        ui->line_edit->setText(pathname);

        if (pathname != "") {
            // 以只读的方式打开选择的文件
            QFile file(pathname);
            file.open(QIODevice::ReadOnly);

            QFileInfo info(pathname);

            QString string;
            string += QString("File Name: ") + info.fileName() + QString("\n");
            string += QString("File Path: ") + info.filePath() + QString("\n");
            string += QString("File Size: ") + QString::number(info.size()) + QString("\n");
            string += QString("File Suffix: ") + info.suffix() + QString("\n");

            ui->text_browser->setText(string);

            file.close();
        }
    });

}

Widget::~Widget()
{
    delete ui;
}

